﻿@inherits BaseHeadListForm<BillInfo, BillListInfo>

<Tabs Animated>
    <ChildContent>
        <TabPane Key="1" Tab="基本信息">
            <BillHeadTypeForm Form="Model" ShowAction>
                <ChildContent>
                    <AntRow>
                        <DataItem Span="6" Label="业务单号" Required>
                            <AntInput Disabled @bind-Value="@context.BillNo" />
                        </DataItem>
                        <DataItem Span="6" Label="单证日期" Required>
                            <AntDatePicker @bind-Value="@context.BillDate" />
                        </DataItem>
                        <DataItem Span="6" Label="商业伙伴" Required>
                            <PartnerPicker Value="@context.Partner" AllowClear Type="@GetPartnerPickerType(context)"
                                           ValueChanged="e=>context.Partner=e?.ToString()" />
                        </DataItem>
                    </AntRow>
                    <AntRow>
                        <DataItem Span="6" Label="合同号">
                            <AntInput @bind-Value="@context.ContractNo" />
                        </DataItem>
                        <DataItem Span="6" Label="发票号">
                            <AntInput @bind-Value="@context.InvoiceNo" />
                        </DataItem>
                        <DataItem Span="6" Label="结算方式" Required>
                            <AntRadioGroup @bind-Value="@context.SettleMode" Category="@AppConstant.SettleMode" ButtonStyle="RadioButtonStyle.Solid" />
                        </DataItem>
                        <DataItem Span="6" Label="总金额">
                            <AntDecimal Disabled @bind-Value="@context.TotalAmount" /> 元
                        </DataItem>
                    </AntRow>
                    <AntRow>
                        <DataItem Span="6" Label="物流公司">
                            <AntInput @bind-Value="@context.Logistics" />
                        </DataItem>
                        <DataItem Span="6" Label="物流单号">
                            <AntInput @bind-Value="@context.LogisticsNo" />
                        </DataItem>
                        <DataItem Span="6" Label="物流费用">
                            <AntDecimal @bind-Value="@context.LogisticsFee" /> 元
                        </DataItem>
                        @if (context.Type == BillType.ImportReturn || context.Type == BillType.ExportReturn)
                        {
                            <DataItem Span="6" Label="被退单号">
                                <AntInput Disabled @bind-Value="@context.ReturnNo" />
                            </DataItem>
                        }
                    </AntRow>
                    <AntRow>
                        <DataItem Span="12" Label="备注">
                            <AntTextArea @bind-Value="@context.Note" />
                        </DataItem>
                        <DataItem Span="12" Label="附件">
                            <KUpload @ref="upload" ReadOnly="Model.IsView" Value="@context.Files"
                                     IsButton="!Model.Data.IsNew" OnFilesChanged="OnFilesChangedAsync" />
                        </DataItem>
                    </AntRow>
                </ChildContent>
                <ListContent>
                    <KFlexSpace>
                        <KTitle Text="货品明细" />
                        @if (!Model.IsView)
                        {
                            <KButton Icon="plus" Name="添加" OnClick="OnAdd" />
                        }
                    </KFlexSpace>
                    <BillListTypeTable DataSource="ListItems" IsView="Model.IsView" HidePagination ScrollY="200px">
                        <IntegerColumn Title="序号" Width="60" Fixed="ColumnFixPlacement.Left">@context.SeqNo</IntegerColumn>
                        <TableColumn Title="商品名称" Width="120" Fixed="ColumnFixPlacement.Left" Value="@context.Name">
                            <AntSelectCode @bind-Value="@context.Code" DataSource="GoodsCodes" OnSelectedItemChanged="e => OnGoodsChange(e, context)" />
                        </TableColumn>
                        <StringColumn Title="商品类别" Width="100">@context.Category</StringColumn>
                        <StringColumn Title="规格型号" Width="150">@context.Model</StringColumn>
                        <StringColumn Title="产地" Width="100">@context.Producer</StringColumn>
                        <StringColumn Title="计量单位" Width="100">@context.Unit</StringColumn>
                        <TableColumn Title="数量" Width="100" Value="@context.Qty">
                            <AntInteger @bind-Value="@context.Qty" OnChange="e => OnGoodsChange(1, context)" />
                        </TableColumn>
                        <TableColumn Title="单价" Width="100" Value="@context.Price">
                            <AntDecimal @bind-Value="@context.Price" OnChange="e => OnGoodsChange(2, context)" />
                        </TableColumn>
                        <TableColumn Title="金额" Width="100" Value="@context.Amount">
                            <AntDecimal @bind-Value="@context.Amount" OnChange="e => OnGoodsChange(3, context)" />
                        </TableColumn>
                        <TableColumn Title="备注" Width="100" Value="@context.Note">
                            <AntInput @bind-Value="@context.Note" />
                        </TableColumn>
                        @if (!Model.IsView)
                        {
                            <ActionColumn Title="操作" Align="ColumnAlign.Center" Width="180" Fixed="ColumnFixPlacement.Right">
                                <KButton Name="上移" OnClick="e => OnMoveUp(context)" />
                                <KButton Name="下移" OnClick="e => OnMoveDown(context)" />
                                <KButton Name="删除" OnClick="e => OnDelete(context)" Danger />
                            </ActionColumn>
                        }
                        <SummaryRow>
                            <SummaryCell Fixed="ColumnFixPlacement.Left">合计</SummaryCell>
                            <SummaryCell Fixed="ColumnFixPlacement.Left" />
                            <SummaryCell />
                            <SummaryCell />
                            <SummaryCell />
                            <SummaryCell />
                            <SummaryCell>@ListItems.Sum(l => l.Qty)</SummaryCell>
                            <SummaryCell />
                            <SummaryCell>@ListItems.Sum(l => l.Amount)</SummaryCell>
                            <SummaryCell />
                            @if (!Model.IsView)
                            {
                                <SummaryCell />
                            }
                        </SummaryRow>
                    </BillListTypeTable>
                </ListContent>
            </BillHeadTypeForm>
        </TabPane>
        <TabPane Key="2" Tab="流程记录">
            <FlowLogGrid BizId="@Model.Data.Id" />
        </TabPane>
    </ChildContent>
    <TabBarExtraContentRight>
        <KTag Text="@Model.Data.Status" />
    </TabBarExtraContentRight>
</Tabs>